package com.zhongli.devplatform.utils;

import net.sf.cglib.beans.BeanCopier;

import java.util.ArrayList;
import java.util.List;

public class BeanCopierUtil {

    public static <T> T copy(Object src, Class<T> c) {
        try {
            T t = c.newInstance();
            BeanCopier.create(src.getClass(), c, false).copy(src, t, null);
            return t;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }

    public static <T> List<T> copy(List srcList, Class<T> c) {
        try {
            List<T> newList = new ArrayList<>();
            for (Object src : srcList) {
                T t = c.newInstance();
                BeanCopier.create(src.getClass(), c, false).copy(src, t, null);
                newList.add(t);
            }
            return newList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }

}
